(function(iot,dev){
    factoryList = ["HD1","HD2","ZZ","DL","XY","HDPT","ZZPT"];
    similarFactoryList = ["ZZ","XY","DL","HD1","HD2","CZ","WH"];
    legendList = ["水", "燃气", "冷量", "压缩空气", "电", "   其他"];
    workshopList = ["冲压车间", "总装车间", "焊装车间", "涂装车间", "树脂车间", "铸造车间"];

    carbonRowTimeModulus = {
        "郑州工厂" : {
            2014 : {
                ele : 0.742,
                gas : 2.36
            },
            2015 : {
                ele : 0.742,
                gas : 2.36
            },
            2016 : {
                ele : 0.742,
                gas : 2.36
            },
            2017 : {
                ele : 0.734,
                gas : 2.36
            },
            2018 : {
                ele : 0.734,
                gas : 2.36
            },
            2019 : {
                ele : 0.5271,
                gas : 2.355
            }

        },
        "花都一工厂" : {
            2014 : {
                ele : 0.742,
                gas : 2.355
            },
            2015 : {
                ele : 0.742,
                gas : 2.355
            },
            2016 : {
                ele : 0.742,
                gas : 2.355
            },
            2017 : {
                ele : 0.734,
                gas : 2.355
            },
            2018 : {
                ele : 0.734,
                gas : 2.355
            },
            2019 : {
                ele : 0.5271,
                gas : 2.355
            }
        }
    };

    costTimeModulus = {
        "郑州工厂" : {
            2014 : {
                ele : 0.742,
                gas : 2.36
            },
            2015 : {
                ele : 0.742,
                gas : 2.36
            },
            2016 : {
                ele : 0.742,
                gas : 2.36
            },
            2017 : {
                ele : 0.734,
                gas : 2.36
            },
            2018 : {
                ele : 0.734,
                gas : 2.36
            },
            2019 : {
                ele : 0.734,
                gas : 2.36
            }
        },
        "花都一工厂" : {
            2014 : {
                ele : 0.61,
                gas : 3.28
            },
            2015 : {
                ele : 0.69,
                gas : 3.28
            },
            2016 : {
                ele : 0.66,
                gas : 3.54
            },
            2017 : {
                ele : 0.62,
                gas : 3.54
            },
            2018 : {
                ele : 0.54,
                gas : 3.67
            },
            2019 : {
                ele : 0.51,
                gas : 3.68
            }
        }
    };
    frameworkIdToDevSn = {
        "郑州工厂" : {
            713 :{
                ele : 'E001',
                gas : 'G001'
            },
            1058 :{
                ele : 'E009'
            },
            1059 :{
                ele : 'E070'
            },
            1061 :{
                ele : 'E276'
            },
            1062 :{
                ele : 'E037',
                gas : 'G059'
            },
            1060 :{
                ele : 'E401',
                gas : 'G002'
            },
            719 :{
                ele : 'E001',
                gas : 'G001'
            },
            1063 :{
                ele : 'E009'
            },
            1064 :{
                ele : 'E070'
            },
            1066 :{
                ele : 'E276'
            },
            1067 :{
                ele : 'E037',
                gas : 'G059'
            },
            1065 :{
                ele : 'E401',
                gas : 'G002'
            }
        },
        "花都一工厂" : {
            1081 :{
                ele : 'HDC001',
                gas : 'HDE001'
            },
            1365 :{
                ele : 'HDC002'
            },
            1405 :{
                ele : 'HDC003'
            },
            1485 :{
                ele : 'HDC005'
            },
            1445 :{
                ele : 'HDC004',
                gas : 'HDE004'
            },
            1525 :{
                ele : 'HDC007',
                gas : 'HDE007'
            },
            1565 :{
                ele : 'HDC006'
            },
            1082 :{
                ele : 'HDC001',
                gas : 'HDE001'
            },
            1366 :{
                ele : 'HDC002'
            },
            1406 :{
                ele : 'HDC003'
            },
            1486 :{
                ele : 'HDC005'
            },
            1446 :{
                ele : 'HDC004',
                gas : 'HDE004'
            },
            1526 :{
                ele : 'HDC007',
                gas : 'HDE007'
            },
            1566 :{
                ele : 'HDC006'
            }
        }
    };

    /**
     * 获取工厂子级占比参数
     * @param workSpaceId
     */
    function getFactoryParam (factoryName) {
        if (!factoryName){
            return;
        }

        var db = iot.db();
        var carbonRowToEleAndGas = db.qry("SELECT * FROM `energy_struc` where type = '碳排' and `level` <= 1\n" +
            "UNION all\n" +
            "select * from `energy_struc` where type = '电' and `level` <= 1\n" +
            "union all\n" +
            "select * from `energy_struc` where type = '燃气' and `level` <= 1;");
        if (carbonRowToEleAndGas){
            var result = {}
            var resultItem = {
                ele : 0,
                gas : 0
            }
            var id;
            carbonRowToEleAndGas.forAll(function (item) {
                if (factoryName === item.name && item.type === "碳排"){
                    id = item.id
                    result[item.id] = resultItem
                }
                if (factoryName === item.name && item.type === "电"){
                    resultItem.ele = item.id
                }
                if (factoryName === item.name && item.type === "燃气"){
                    resultItem.gas = item.id
                }
            });
            return result;
        }
    }

    /**
     * 根据时间获取上一年的时间
     * @param time
     */
    function getPreYearTime(time) {
        var preYear = time.substring(0, 4) - 1;
        return preYear + time.substring(4, time.length);
    }

    /**
     * 通过时间获取年份加后面的月份，天
     * @param year
     * @param time
     */
    function getTime(year, time) {
        if (time.length() > 4) {
            return year + time.substring(4, time.length());
        }
        return year;
    }

    /**
     * 根据time的格式获取当前时间
     * @param time
     */
    function getCurrentTimeByType(timeType) {
        var date = new Date;
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hour = date.getHours();
        month = (month < 10 ? "0" + month : month);
        day = (day < 10 ? "0" + day : day);
        hour = (hour < 10 ? "0" + hour : hour);

        var typeTime = {
            'year': month,
            'month': day,
            'day': hour
        };
        var currTime = {
            'year': year,
            'month': year + "-" + month,
            'day': year + "-" + month + "-" + day
        };
        var result = {
            typeTime : typeTime[timeType],
            currTime : currTime[timeType]
        }
        return result;
    }

    /**
     * 返回近4年数组
     * @param time
     */
    function getNearlyFourYears(time) {
        var result = iot.list();
        var year = time.substring(0, 4);
        for (var index = 3; index >= 0; index--){
            result.add(year - index + '');
        }
        return result;
    }

    /**
     * 根据时间返回对应时间数组
     * @param time
     */
    function getTimeList(time) {
        var timeObj = dtime.parseStringToDateTimeViaPattern(time);
        var times = 0;
        switch (time.length) {
            case 4:
                times=timeObj.monthOfYear().getMaximumValue();
                break;
            case 7:
                times=timeObj.dayOfMonth().getMaximumValue();
                break;
            case 10:
                times=timeObj.hourOfDay().getMaximumValue() + 1;
                break;
            case 13:
                times=timeObj.minuteOfHour().getMaximumValue() + 1;
                break;
            default:
                break;
        }
        var result = iot.list();
        var start = 1;
        var end = times;
        if (time.length >= 10){
            start = 0;
            end = times - 1;
        }
        for (var index = start; index <= end; index++){
            if (index < 10){
                index = "0" + index;
            }
            result.add(index + "");
        }

        return result;
    }

    /**
     * 通过工厂名称获取工厂+工厂车间的名称
     * @param factory
     * @param workSpaceName
     * @returns {*}
     */
    function getFactoryWorkShop(factory, workSpaceName) {
        var index = workSpaceName.indexOf("/");
        if (index > -1) {
            return factory + workSpaceName.substring(index, workSpaceName.length());
        }
        return factory;
    }

    /**
     * 对数据的小数点保留规则判断
     * @param number
     */
    function decimalRetainRule (number) {
        number = parseFloat(number)
        if (!number && number === 0) {
            return 0;
        }
        var numberFormate = iot.getNumberFormat("0.0");
        if (number > 100) {
            return parseInt(number);
        } else {
            return numberFormate.format(number);
        }
    }

    /**
     * 获取工厂名称
     * @param workSpaceName
     */

    function getFactoryName (workSpaceName) {
        var arr = workSpaceName.split("/");
        return arr.length > 1 ? arr[1] : "PV";
    }




// print('start dev Pre Self js...\n');
//
// print('set default pick fun...');

    dev.pickFun = null;



// var a = {};
// a.fuck = function () {
//     print('fuck...');
// }
// a.fuck();t
    factoryList = ["HD1","HD2","ZZ","DL","XY","HDPT","ZZPT"];
    similarFactoryList = ["ZZ","XY","DL","HD1","HD2","CZ","WH"];
    legendList = ["水", "燃气", "冷量", "压缩空气", "电", "   其他"];
    workshopList = ["冲压车间", "总装车间", "焊装车间", "涂装车间", "树脂车间", "铸造车间"];

    carbonRowTimeModulus = {
        "郑州工厂" : {
            2014 : {
                ele : 0.742,
                gas : 2.36
            },
            2015 : {
                ele : 0.742,
                gas : 2.36
            },
            2016 : {
                ele : 0.742,
                gas : 2.36
            },
            2017 : {
                ele : 0.734,
                gas : 2.36
            },
            2018 : {
                ele : 0.734,
                gas : 2.36
            },
            2019 : {
                ele : 0.5271,
                gas : 2.355
            }

        },
        "花都一工厂" : {
            2014 : {
                ele : 0.742,
                gas : 2.355
            },
            2015 : {
                ele : 0.742,
                gas : 2.355
            },
            2016 : {
                ele : 0.742,
                gas : 2.355
            },
            2017 : {
                ele : 0.734,
                gas : 2.355
            },
            2018 : {
                ele : 0.734,
                gas : 2.355
            },
            2019 : {
                ele : 0.5271,
                gas : 2.355
            }
        }
    };

    costTimeModulus = {
        "郑州工厂" : {
            2014 : {
                ele : 0.742,
                gas : 2.36
            },
            2015 : {
                ele : 0.742,
                gas : 2.36
            },
            2016 : {
                ele : 0.742,
                gas : 2.36
            },
            2017 : {
                ele : 0.734,
                gas : 2.36
            },
            2018 : {
                ele : 0.734,
                gas : 2.36
            },
            2019 : {
                ele : 0.734,
                gas : 2.36
            }
        },
        "花都一工厂" : {
            2014 : {
                ele : 0.61,
                gas : 3.28
            },
            2015 : {
                ele : 0.69,
                gas : 3.28
            },
            2016 : {
                ele : 0.66,
                gas : 3.54
            },
            2017 : {
                ele : 0.62,
                gas : 3.54
            },
            2018 : {
                ele : 0.54,
                gas : 3.67
            },
            2019 : {
                ele : 0.51,
                gas : 3.68
            }
        }
    };
    frameworkIdToDevSn = {
        "郑州工厂" : {
            713 :{
                ele : 'E001',
                gas : 'G001'
            },
            1058 :{
                ele : 'E009'
            },
            1059 :{
                ele : 'E070'
            },
            1061 :{
                ele : 'E276'
            },
            1062 :{
                ele : 'E037',
                gas : 'G059'
            },
            1060 :{
                ele : 'E401',
                gas : 'G002'
            },
            719 :{
                ele : 'E001',
                gas : 'G001'
            },
            1063 :{
                ele : 'E009'
            },
            1064 :{
                ele : 'E070'
            },
            1066 :{
                ele : 'E276'
            },
            1067 :{
                ele : 'E037',
                gas : 'G059'
            },
            1065 :{
                ele : 'E401',
                gas : 'G002'
            }
        },
        "花都一工厂" : {
            1081 :{
                ele : 'HDC001',
                gas : 'HDE001'
            },
            1365 :{
                ele : 'HDC002'
            },
            1405 :{
                ele : 'HDC003'
            },
            1485 :{
                ele : 'HDC005'
            },
            1445 :{
                ele : 'HDC004',
                gas : 'HDE004'
            },
            1525 :{
                ele : 'HDC007',
                gas : 'HDE007'
            },
            1565 :{
                ele : 'HDC006'
            },
            1082 :{
                ele : 'HDC001',
                gas : 'HDE001'
            },
            1366 :{
                ele : 'HDC002'
            },
            1406 :{
                ele : 'HDC003'
            },
            1486 :{
                ele : 'HDC005'
            },
            1446 :{
                ele : 'HDC004',
                gas : 'HDE004'
            },
            1526 :{
                ele : 'HDC007',
                gas : 'HDE007'
            },
            1566 :{
                ele : 'HDC006'
            }
        }
    };

    /**
     * 获取工厂子级占比参数
     * @param workSpaceId
     */
    function getFactoryParam (factoryName) {
        if (!factoryName){
            return;
        }

        var db = iot.db();
        var carbonRowToEleAndGas = db.qry("SELECT * FROM `energy_struc` where type = '碳排' and `level` <= 1\n" +
            "UNION all\n" +
            "select * from `energy_struc` where type = '电' and `level` <= 1\n" +
            "union all\n" +
            "select * from `energy_struc` where type = '燃气' and `level` <= 1;");
        if (carbonRowToEleAndGas){
            var result = {}
            var resultItem = {
                ele : 0,
                gas : 0
            }
            var id;
            carbonRowToEleAndGas.forAll(function (item) {
                if (factoryName === item.name && item.type === "碳排"){
                    id = item.id
                    result[item.id] = resultItem
                }
                if (factoryName === item.name && item.type === "电"){
                    resultItem.ele = item.id
                }
                if (factoryName === item.name && item.type === "燃气"){
                    resultItem.gas = item.id
                }
            });
            return result;
        }
    }

    /**
     * 根据时间获取上一年的时间
     * @param time
     */
    function getPreYearTime(time) {
        var preYear = time.substring(0, 4) - 1;
        return preYear + time.substring(4, time.length);
    }

    /**
     * 通过时间获取年份加后面的月份，天
     * @param year
     * @param time
     */
    function getTime(year, time) {
        if (time.length() > 4) {
            return year + time.substring(4, time.length());
        }
        return year;
    }

    /**
     * 根据time的格式获取当前时间
     * @param time
     */
    function getCurrentTimeByType(timeType) {
        var date = new Date;
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var hour = date.getHours();
        month = (month < 10 ? "0" + month : month);
        day = (day < 10 ? "0" + day : day);
        hour = (hour < 10 ? "0" + hour : hour);

        var typeTime = {
            'year': month,
            'month': day,
            'day': hour
        };
        var currTime = {
            'year': year,
            'month': year + "-" + month,
            'day': year + "-" + month + "-" + day
        };
        var result = {
            typeTime : typeTime[timeType],
            currTime : currTime[timeType]
        }
        return result;
    }

    /**
     * 返回近4年数组
     * @param time
     */
    function getNearlyFourYears(time) {
        var result = iot.list();
        var year = time.substring(0, 4);
        for (var index = 3; index >= 0; index--){
            result.add(year - index + '');
        }
        return result;
    }

    /**
     * 根据时间返回对应时间数组
     * @param time
     */
    function getTimeList(time) {
        var timeObj = dtime.parseStringToDateTimeViaPattern(time);
        var times = 0;
        switch (time.length) {
            case 4:
                times=timeObj.monthOfYear().getMaximumValue();
                break;
            case 7:
                times=timeObj.dayOfMonth().getMaximumValue();
                break;
            case 10:
                times=timeObj.hourOfDay().getMaximumValue() + 1;
                break;
            case 13:
                times=timeObj.minuteOfHour().getMaximumValue() + 1;
                break;
            default:
                break;
        }
        var result = iot.list();
        var start = 1;
        var end = times;
        if (time.length >= 10){
            start = 0;
            end = times - 1;
        }
        for (var index = start; index <= end; index++){
            if (index < 10){
                index = "0" + index;
            }
            result.add(index + "");
        }

        return result;
    }

    /**
     * 通过工厂名称获取工厂+工厂车间的名称
     * @param factory
     * @param workSpaceName
     * @returns {*}
     */
    function getFactoryWorkShop(factory, workSpaceName) {
        var index = workSpaceName.indexOf("/");
        if (index > -1) {
            return factory + workSpaceName.substring(index, workSpaceName.length());
        }
        return factory;
    }

    /**
     * 对数据的小数点保留规则判断
     * @param number
     */
    function decimalRetainRule (number) {
        number = parseFloat(number)
        if (!number && number === 0) {
            return 0;
        }
        var numberFormate = iot.getNumberFormat("0.0");
        if (number > 100) {
            return parseInt(number);
        } else {
            return numberFormate.format(number);
        }
    }

    /**
     * 获取工厂名称
     * @param workSpaceName
     */

    function getFactoryName (workSpaceName) {
        var arr = workSpaceName.split("/");
        return arr.length > 1 ? arr[1] : "PV";
    }




// 碳排同类对比
    var numberFormate = iot.getNumberFormat("0.00");
// 系数
    var modulus = {
        2014 : {
            ele : 0.742,
            gas : 2.36
        },
        2015 : {
            ele : 0.742,
            gas : 2.36
        },
        2016 : {
            ele : 0.742,
            gas : 2.36
        },
        2017 : {
            ele : 0.734,
            gas : 2.36
        },
        2018 : {
            ele : 0.734,
            gas : 2.36
        }
    }
    var subLevelDevMap = {
        713 :{
            ele : 'E001',
            gas : 'G001'
        },
        714 :{
            ele : 'E009'
        },
        715 :{
            ele : 'E070'
        },
        716 :{
            ele : 'E276'
        },
        717 :{
            ele : 'E037',
            gas : 'G059'
        },
        718 :{
            ele : 'E401',
            gas : 'G002'
        }

    }

    /**
     * 通过空间id和时间获取用电对应的sql
     * @param workSpace
     * @param time
     * @returns {string}
     */
    function getEleSql(workSpace, time) {
        return "select SUM(win.dvalue) totalSum " +
            " FROM iot_dev_data_win win " +
            " LEFT JOIN iot_dev dev on dev.id=win.dev_id " +
            " where 1=1 " +
            " and dev.sn='"+subLevelDevMap[workSpace].ele+"'" +
            " and win.data_type = '_用量'" +
            " and win.the_time like '"+ time +"%'";
    }

    /**
     * 通过空间id和时间获取燃气对应的sql
     * @param workSpace
     * @param time
     * @returns {string}
     */
    function getGasSql(workSpace, time) {
        return "select SUM(win.dvalue) totalSum " +
            " FROM iot_dev_data_win win " +
            " LEFT JOIN iot_dev dev on dev.id=win.dev_id " +
            " where 1=1 " +
            " and dev.sn='"+ subLevelDevMap[workSpace].gas +"'" +
            " and win.data_type = '用量'" +
            " and win.the_time like '"+ time +"%'";
    }

    dev.action = function(resp,param){
        //是否算总还是单
        var totalOrSingle = param.selectType;
        if (totalOrSingle == null){
            totalOrSingle = "total";
        }
        var theTime = param.time;
        var preYearTime = getPreYearTime(theTime);
        var workSpace = param.workSpace;
        var db = iot.db();
        var timeSub = parseInt(theTime.substring(0, 4));

        var result1 = db.queryOne("select level, name, pid from energy_struc where id = " + workSpace);
        var strSql;
        if (result1.level == '1') {
            strSql = " and level = 1";
        } else {
            strSql = " and level = " + result1.level + " and name = '" + result1.name + "'";
        }

        //获取当前选择年份产量
        var yieldResult = db.queryOne("select SUM(dvalue) totalSum from iot_dev_data_win" +
            " where dev_id = 278 and the_time like '"+ theTime +"%'");
        var totalYield = yieldResult.totalSum;

        // 计算郑州工厂上一年产量
        var preYearSingleResult = db.queryOne("select SUM(dvalue) totalSum from iot_dev_data_win" +
            " where dev_id = 278 and the_time like '"+ preYearTime +"%'");
        var preYearYield = 0;
        if (preYearSingleResult.totalSum) {
            preYearYield = preYearSingleResult.totalSum;
        }

        var result = 0;
        if (timeSub >= 2019) {
            // 当前年份的用量
            result = db.qry("select es.factory, res.es_id, res.totalSum, es.name from energy_struc es " +
                " INNER JOIN (select esp.energy_struc_id es_id, SUM(dev_win.dvalue) totalSum " +
                " from iot_dev_data_win dev_win," +
                " (select dev_id, name, energy_struc_id from energy_struc_prop where type = 2 and name = '碳排'" +
                " and energy_struc_id in (select id from energy_struc where type = '碳排'" + strSql + ")) esp " +
                " where dev_win.dev_id = esp.dev_id and dev_win.data_type = esp.name" +
                " and dev_win.the_time like '"+ theTime +"%'" +
                " group by esp.energy_struc_id) res" +
                " on es.id = res.es_id order by totalSum desc");

            // 计算郑州工厂上一年总量的同比的数据
            var preYearResult = db.queryOne("select esp.name,SUM(dev_win.dvalue) totalSum from iot_dev_data_win dev_win," +
                " (select * from energy_struc_prop where type = 2 and name = '碳排' and energy_struc_id = "+ workSpace +") esp" +
                " where dev_win.dev_id = esp.dev_id" +
                " and dev_win.data_type = esp.name" +
                " and dev_win.the_time like '"+ preYearTime +"%'");
            var preYearTotalSum = 0;
            if (preYearResult.totalSum) {
                preYearTotalSum = preYearResult.totalSum;
            }

            var factoryList = iot.list();
            var count = 0;
            var preValue = "";
            result.forAll(function (item) {
                // 如果数值一样，则排名不变化
                if (!item.totalSum.equals(preValue)) {
                    preValue = item.totalSum;
                    ++count;
                }
                //判断当前选择总数还是单车
                if (totalOrSingle.equals("total")) {
                    var increase = "0%";
                    if (item.totalSum && preYearTotalSum != 0) {
                        var gain = (item.totalSum - preYearTotalSum) / preYearTotalSum; // 计算同比差值
                        increase = (gain * 100).toFixed(1) + "%";
                    }
                    factoryList.add({rank: count, name: item.factory, workshop: item.name, useNum: numberFormate.format(item.totalSum), increase: increase});
                }else if (totalOrSingle.equals("single")) {
                    var sum = 0; // 当前年份的单车用量
                    if (item.totalSum && totalYield){
                        sum = item.totalSum / totalYield;
                    }
                    var increase = "0%";
                    var preYearSingle = 0;
                    if (preYearTotalSum != 0 && preYearYield != 0) {
                        preYearSingle = preYearTotalSum / preYearYield; // 上一年的单车用量
                        if (sum != 0 && preYearSingle != 0) {
                            var toFixedSum = numberFormate.format(sum);
                            var toFixedPreYearSingle = numberFormate.format(preYearSingle);
                            var gain = (toFixedSum - toFixedPreYearSingle) / toFixedPreYearSingle;
                            increase = (gain * 100).toFixed(1) + "%";
                        }
                    }
                    factoryList.add({rank: count, name: item.factory, workshop: item.name, useNum: numberFormate.format(sum), increase: increase});
                }
            })

            // 如果工厂数据没有，则赋值为0
            for (var i in similarFactoryList) {
                var flag = false;
                for (var key in factoryList) {
                    if (similarFactoryList[i].equals(factoryList[key].name)) {
                        flag = true;
                    }
                }
                if (!flag) {
                    factoryList.add({rank: count + 1, name: similarFactoryList[i], workshop: result1.name, useNum: 0, increase: "0%"});
                }
            }
            var jsData = {
                content : factoryList
            };
            resp.setJsData(jsData);

        } else { // 计算2019年之前的数据

            // 今年的计算统计数据
            var totalCarbon = 0;
            var electricityResult = 0;
            var gasResult = 0;
            // 定义上一年数据的变量
            var preTotalCarbon = 0;
            var preYearElectricityResult = 0;
            var preYearGasResult = 0;
            //工厂  E001._用量*系数 +  G001.用量*系数
            // print("1111")
            if(subLevelDevMap[workSpace] && subLevelDevMap[workSpace].ele){
                // print("22222")
                electricityResult = db.queryOne(getEleSql(workSpace, theTime));
                preYearElectricityResult = db.queryOne(getEleSql(workSpace, preYearTime));
            }
            if(subLevelDevMap[workSpace] && subLevelDevMap[workSpace].gas){
                gasResult = db.queryOne(getGasSql(workSpace, theTime));
                preYearGasResult = db.queryOne(getGasSql(workSpace, preYearTime));
            }
            // 计算当前年的数据
            if(electricityResult && electricityResult.totalSum){
                totalCarbon = electricityResult.totalSum * modulus[timeSub].ele;
            }
            if(gasResult && gasResult.totalSum){
                totalCarbon = totalCarbon + gasResult.totalSum * modulus[timeSub].gas;
            }
            // 上一年的计算数据
            if (preYearElectricityResult.totalSum) {
                preTotalCarbon = preYearElectricityResult.totalSum * modulus[timeSub].ele;
            }
            if (preYearGasResult.totalSum) {
                preTotalCarbon = preTotalCarbon + preYearGasResult.totalSum * modulus[timeSub].gas;
            }
            var factoryList = iot.list();

            for (var index in similarFactoryList) {
                if (similarFactoryList[index].equals()) {

                }
            }

            //判断当前选择总数还是单车
            if (totalOrSingle.equals("total")) {
                var increase = "0%";
                if (totalCarbon != 0 && preTotalCarbon != 0) {
                    var gain = (totalCarbon - preTotalCarbon) / preTotalCarbon;
                    increase = (gain * 100).toFixed(1) + "%";
                }
                factoryList.add({rank: 1, name: 'ZZ', workshop: result1.name, useNum: numberFormate.format(totalCarbon), increase: increase});
            }else if (totalOrSingle.equals("single")) {
                // 当前年的单车碳排
                if (totalCarbon != 0 && totalYield != 0){
                    totalCarbon = totalCarbon / totalYield;
                }
                var preYearSingleCarbon = 0; // 上一年的单车碳排
                // 计算上一年的单车碳排
                if (preTotalCarbon != 0 && preYearYield != 0) {
                    preYearSingleCarbon = preTotalCarbon / preYearYield;
                }
                var increase = "0%";
                // 计算同比涨幅
                if (totalCarbon != 0 && preYearSingleCarbon != 0) {
                    var toFixedTotalCarbon = numberFormate.format(totalCarbon);
                    var toFixedPreYearSingleCarbon = numberFormate.format(preYearSingleCarbon);
                    var gain = (toFixedTotalCarbon - toFixedPreYearSingleCarbon) / toFixedPreYearSingleCarbon;
                    increase = (gain * 100).toFixed(1) + "%";
                }
                factoryList.add({rank: 1, name: 'ZZ', workshop: result1.name, useNum: numberFormate.format(totalCarbon), increase: increase});
            }
            var jsData = {
                content : factoryList
            };
            resp.setJsData(jsData);
        }
    }


})(iot,dev);
